// pages/myPages/personalCenter/creditCard/addCreditCard/getVerifyingCode/getVerifyingCode.js
var interval = null
Page({

  /**
   * 页面的初始数据
   */
  data: {
    showView: true,
    userNameInput: '',
    userN: '',
    date: '请选择日期',
    fun_id: 2,
    time: '获取验证码', //倒计时 
    currentTime: 60,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  
  },
  userNameInput: function (e) {
    this.setData({
      userN: e.detail.value
    })
    this.loginBtnClick();
  },
  loginBtnClick: function () {
    if (this.data.userN.length != 0) {
      this.setData({
        showView: false
      })
    } else {
      this.setData({
        showView: true
      })
    }
  },
  getCode: function (options) {
    var that = this;
    var currentTime = that.data.currentTime
    interval = setInterval(function () {
      currentTime--;
      that.setData({
        time: currentTime + 's后重新获取'
      })
      if (currentTime <= 0) {
        clearInterval(interval)
        that.setData({
          time: '获取验证码',
          currentTime: 60,
          disabled: false
        })
      }
    }, 1000)
  },
  getVerificationCode() {
    var that = this

    that.getCode();

    that.setData({
      time: '60s后重新获取',
      disabled: true
    })
  },
  getVerifyingCode: function (e) {
    if (this.data.showView == false) {
      wx.navigateTo({
        url: './validateFinish/validateFinish'
      })
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      setLang: wx.T.locale == "zh-Hans" ? wx.T.locales['zh-Hans'] : wx.T.locales['en']

    })
    wx.setNavigationBarTitle({
      title: wx.T.locale == "zh-Hans" ? wx.T.locales['zh-Hans'].VerifyPhoneNumber : wx.T.locales['en'].VerifyPhoneNumber
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})